﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vowei.Data;
using Vowei.Core.Models;
using Vowei.Web;

namespace vowei.web.Controllers
{
    public class ScmController : G18nController
    {
        private IVoweiContext _context;
        public ScmController(IVoweiContext context)
        {
            _context = context;
        }

        public ActionResult Index(Guid id)
        {
            var project = _context.Projects.Find(id);
            if (project == null)
                throw new ArgumentException(string.Format(T("找不到ID为{0}的项目!"), id));

            ViewData["Project"] = project;
            var cset = _context.ChangeSet.Query.Where(c => c.Project.ID == id);

            return View(cset);
        }

        public ActionResult Details(string name, Guid milestone)
        {
            var changeset = _context.ChangeSet.Include("Project").Include("Tickets").Query.FirstOrDefault(
                c => c.Title == name && c.Project.ID.CompareTo(milestone) == 0);
            if (changeset == null)
            {
                throw new ArgumentException(
                    string.Format(T("找不到第[{0}]次签入!"), name));
            }

            return View(changeset);
        }
    }
}
